package com.zzyl.controller;



import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    ResourceService resourceService;

    @PostMapping("/list")
    @ApiOperation(value = "资源列表",notes = "资源列表")
    @ApiOperationSupport(includeParameters = {"resourceDto.dataState","resourceDto.resourceNo"})
    public ResponseResult<List<ResourceVo>>  resourceList(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo>  ResourceVo = resourceService.resourceList(resourceDto);
        return ResponseResult.success(ResourceVo);
    }

    @PostMapping("/tree")
    @ApiOperation(value = "资源树形",notes = "资源树形")
    @ApiOperationSupport(includeParameters = {"resourceDto.dataState","resourceDto.resourceNo"})
    public ResponseResult<TreeVo> resourceTreeVo(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resource(resourceDto);
        return ResponseResult.success(treeVo);
    }

    @PutMapping
    @ApiOperation(value = "资源添加",notes = "资源添加")
    @ApiOperationSupport(includeParameters = {"resourceDto.dataState","resourceDto.resourceNo","resourceDto.resourceName","resourceDto.resourceType","resourceDto.requestPath","resourceDto.label","resourceDto.sortNo","resourceDto.icon","resourceDto.remark"})
    public ResponseResult<ResourceVo> createResource(@RequestBody ResourceDto resourceDto) {
       Boolean flag = resourceService.createResource(resourceDto);
        return ResponseResult.success(flag);
    }
    @PostMapping("enable")
    @ApiOperation(value = "启用-禁用",notes = "启用-禁用")
    @ApiOperationSupport(includeParameters = {"resourceVo.dataState","resourceVo.resourceNo"})
    public ResponseResult<Boolean> isEnable(@RequestBody ResourceVo resourceVo){
        resourceService.isEnable(resourceVo);
        return ResponseResult.success();
    }
    @DeleteMapping("{resourceNo}")
    @ApiOperation(value = "删除资源",notes = "删除资源")
    @ApiOperationSupport(includeParameters = {"resourceNo"})
    public ResponseResult<Boolean> deleteResource(@PathVariable String resourceNo){
        resourceService.deleteResource(resourceNo);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation(value = "资源修改",notes = "资源修改")
    @ApiOperationSupport(includeParameters = {"resourceDto.dataState","resourceDto.resourceNo","resourceDto.resourceName","resourceDto.resourceType","resourceDto.requestPath","resourceDto.label","resourceDto.sortNo","resourceDto.icon","resourceDto.remark"})
    public ResponseResult<Boolean> updateDept(@RequestBody ResourceDto resourceDto) {
        resourceService.updateDept(resourceDto);
        return ResponseResult.success();
    }
}
